package processing_layer;

/**
 * This class represents an entry in the DB sessions table.
 * It is used in order to pass information from the DB layer to the interface layer,
 * and avoiding the excess usage of ResultSets 
 */
public class CourseSession implements Comparable<CourseSession>
{
	public String courseName;
	public int groupNumber;
	public int day;
	public int startingTime;
	public int endingTime;
	public int duration;
	
	public CourseSession(String courseName, int day, int startingTime, 
			             int endingTime, int duration, int groupNumber)
	{
		super();
		this.courseName = courseName;
		this.groupNumber = groupNumber;
		this.startingTime = startingTime;
		this.endingTime = endingTime;
		this.duration = duration;
		this.day = day;
	}

	@Override
	public int compareTo(CourseSession compared)
	{
		final int BEFORE = -1;
	    final int EQUAL = 0;
	    final int AFTER = 1;

		if (this == compared)
		{
			return EQUAL;
		}
		
		if (this.day < compared.day)
		{
			return BEFORE;
		}
		
		if (this.day > compared.day)
		{
			return AFTER;
		}
		
		// Days are equal
		if (this.startingTime < compared.startingTime)
		{
			return BEFORE;
		}
		
		if (this.startingTime > compared.startingTime)
		{
			return AFTER;
		}
		
		// Starting times are equal
		if (this.endingTime < compared.endingTime)
		{
			return BEFORE;
		}
		
		if (this.endingTime > compared.endingTime)
		{
			return AFTER;
		}
		
		return EQUAL;
	}
}
